package com.whfc.mach.queue;

import com.whfc.common.constant.QueueConst;
import com.whfc.common.util.JSONUtil;
import com.whfc.mach.dto.iot.MachMsg0x08;
import com.whfc.mach.dto.iot.MachWarnRotation;
import com.whfc.mach.manager.MachDataManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Description:
 * @author: xugcheng
 * @version: 1.0
 * @date: 2021-01-08 14:59
 */
@Component
@RabbitListener(queues = QueueConst.MACH_MSG_0X08)
public class MachMsg0x08QueueListener {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private MachDataManager machDataManager;

    @RabbitHandler
    public void process(String msg) {
        try {
            logger.info("mach_msg_0x08,{}", msg);
            MachMsg0x08 reqMsg = JSONUtil.parseObject(msg, MachMsg0x08.class);
            if (reqMsg != null) {
                Integer deviceId = reqMsg.getDeviceId();
                MachWarnRotation rotation = reqMsg.getRotation();
                machDataManager.addMachWarnRotation(deviceId, rotation);
            }

        } catch (Exception ex) {
            logger.error("mach_data,消息处理失败", ex);
        }
    }
}
